package com.wwwarehouse.financialcenter.fragment.moneywarehouse.payment;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.wwwarehouse.common.bean.response.CommonClass;
import com.wwwarehouse.financialcenter.R;
import com.wwwarehouse.financialcenter.customview.AutoClickButton;
import com.wwwarehouse.financialcenter.fragment.base.TheParentFragment;

/**
 * @author Joseph on 2017/11/22.
 *         <p/>
 *         支付状态页面，成功，等待，失败页面
 */

public class PaymentStatusFragment extends TheParentFragment {

    private ImageView mImagStatus;
    private TextView mTvSratus;
    private TextView mTvDescribe;
    private AutoClickButton mBnt ;
    private int status;
    private String billAmount;

    @Override
    protected int getContentId() {
           return R.layout.financial_center_payment_status;
    }

//    @Override
//    protected boolean isRegisterEventBus() {
//        return true;
//    }

    @Override
    protected void init(View view) {
        mImagStatus = findView(view,R.id.img_status);
        mTvSratus = findView(view,R.id.tv_status);
        mTvDescribe = findView(view,R.id.tv_describe);
        mBnt = findView(view,R.id.confirm_btn);
        mBnt.setEnabled(true);
        mBnt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            popFragment();
            }
        });
    }

    @Override
    protected void loadDatas() {
        Bundle bundle = getArguments();
        if (bundle!=null){
            status = bundle.getInt("status");
            billAmount = bundle.getString("billAmount");
            if (status==PaymentFragment.PAY_SUCCESS){
                onSuccess();
            }else if (status==PaymentFragment.PAY_WAIT){
                onWait();
            }else if (status==PaymentFragment.PAY_FAIL){
                onFailure();
            }
        }
    }

    @Override
    public void onSuccess(CommonClass commonClass, int what) {

    }

    @Override
    public void onReLoad(int code) {

    }

    /**
     * 支付成功
     */
    private void onSuccess(){
        mImagStatus.setImageResource(R.drawable.financial_center_successful);
        mTvSratus.setText(R.string.financial_center_success);
        mTvDescribe.setText("成功支付"+billAmount);
    }
    /**
     * 支付等待中
     */
    private void onWait(){
        mImagStatus.setImageResource(R.drawable.financial_center_pay_wait);
        mTvSratus.setText(R.string.financial_center_wait);
        mTvDescribe.setText("正在获取支付结果\n获得结果后会更新账单状态");
    }
    
    /**
     * 支付失败
     */
    private void onFailure(){
        mBnt.setText(R.string.financial_center_back_pay_agin);
        mImagStatus.setImageResource(R.drawable.financial_center_pay_failure);
        mTvSratus.setText(R.string.financial_center_fail);
        mTvSratus.setTextColor(getResources().getColor(R.color.financial_center_colore_f7a82f));
        mTvDescribe.setText("由于第三方支付的问题\n支付"+billAmount+"失败");
    }

//    public void onEventMainThread(PayResultEvent event) {
//        if (event != null) {
//            String msg = event.getMsg();
//            switch (msg){
//                case "success":
//                    onSuccess();
//
//                    break;
//                case "failure":
//                    onFailure();
//
//                    break;
//                case "cancel":
//                    popFragment();
//                    toastAtTop("支付已被您取消");
//
//                    break;
//            }
//
//        }
//    }
}
